package com.tuanzi.loan.business.repository.family.impl;

import com.tuanzi.loan.business.entity.family.LoanUnionForeignChannelInfo;
import com.tuanzi.loan.business.repository.family.custom.LoanUnionForeignChannelInfoRepositoryCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepository;
import com.tuanzi.loan.vo.request.family.LoanUnionForeignChannelInfoRequest;
import org.jooq.impl.TableImpl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import static com.tuanzi.loan.generated.jooq.loan.tables.LoanUnionForeignChannelInfo.LOAN_UNION_FOREIGN_CHANNEL_INFO;

/**
 * User: liangZongXi
 * Create time: 17:06 2018/11/19
 * Description:
 */
@Repository
public class LoanUnionForeignChannelInfoRepositoryImpl extends JOOQBaseRepository implements LoanUnionForeignChannelInfoRepositoryCustom {

    @Override
    public Page<LoanUnionForeignChannelInfo> list(LoanUnionForeignChannelInfoRequest searchRequest, Pageable pageable) {
        fields(LOAN_UNION_FOREIGN_CHANNEL_INFO.fields());
        eq(LOAN_UNION_FOREIGN_CHANNEL_INFO.CHANNEL, searchRequest.getChannelId());
        eq(LOAN_UNION_FOREIGN_CHANNEL_INFO.PRDID, searchRequest.getProductId());
        eq(LOAN_UNION_FOREIGN_CHANNEL_INFO.ACTIVITY_ID, searchRequest.getActivityId());
        return search(pageable, record -> {
            LoanUnionForeignChannelInfo channelInfo = new LoanUnionForeignChannelInfo();
            channelInfo.setId(record.get(LOAN_UNION_FOREIGN_CHANNEL_INFO.ID));
            channelInfo.setActivityId(record.get(LOAN_UNION_FOREIGN_CHANNEL_INFO.ACTIVITY_ID));
            channelInfo.setChannelId(record.get(LOAN_UNION_FOREIGN_CHANNEL_INFO.CHANNEL));
            channelInfo.setProductId(record.get(LOAN_UNION_FOREIGN_CHANNEL_INFO.PRDID));
            channelInfo.setIosDownload(record.get(LOAN_UNION_FOREIGN_CHANNEL_INFO.IOS_DOWNLOAD));
            channelInfo.setAndroidDownload(record.get(LOAN_UNION_FOREIGN_CHANNEL_INFO.ANDROID_DOWNLOAD));
            channelInfo.setIosProductId(record.get(LOAN_UNION_FOREIGN_CHANNEL_INFO.IOSPRDID));
            return channelInfo;
        });
    }

    @Override
    protected TableImpl getTable() {
        return LOAN_UNION_FOREIGN_CHANNEL_INFO;
    }
}
